package com.nf.health.app.customview;

import android.content.Context;
import android.content.res.Resources;
import android.os.Handler;
import android.util.AttributeSet;
import android.widget.HorizontalScrollView;

import com.nf.health.app.R;
import com.nf.health.app.models.DataDetails;
import com.nf.health.app.utils.DensityUtil;

import java.util.List;


/**
 *自定义HorizontalScrollView 滑动监听事件
 * 滑动到最左边，或者是左右边
 */
public class MyCustomserHorizonScrollView extends HorizontalScrollView{
    private int tb;
    private int  xInterval, yInterval;
    private Resources res ;
    private int historyDataSize = 0;//传过来历史记录的集合的大小
    private int horizontalTotleAllLength = 0 ;
    private int verticaltotleAllLength = 0;
    private int screenWidth = 0 ;
    public MyCustomserHorizonScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initData(context);
    }
    private void initData(Context context){
        res = getResources();
        tb = (int) res.getDimension(R.dimen.historyscore_tb);
        xInterval = tb * 5;
        screenWidth = DensityUtil.getScreenIntWidth(context);
    }
    public void setMyScrollPosition(int dataDetailsList){
        this.historyDataSize = dataDetailsList;
        horizontalTotleAllLength = xInterval / 2 + xInterval * dataDetailsList;
        verticaltotleAllLength = getHeight()+200;
        if(screenWidth > horizontalTotleAllLength){//不滑动到最后
            return ;
        }
        //滑动到最后
        srollToPosition(horizontalTotleAllLength);
    }
    public void srollToPosition(final int totleAllLength){
        new Handler().postDelayed((
                new Runnable() {
                    @Override public void run() {

                        scrollTo(totleAllLength, getHeight());

                       /* scrollTo(((RadioButton)rg_price.getChildAt(housePriceIndex)).getLeft()-100,0);*/

                    } }),5);
        //其中 ((RadioButton)rg_price.getChildAt(housePriceIndex)).getLeft()-100
    }
}
